<template>
	<view class="house-pages">
		<SelectHouse :info="selectInfo"></SelectHouse>
		<template v-if="list.length>0">
			<view class="info-block" v-for="item in list" :key="item.id">
				<view class="rent-info">
					<image :src="imgStorage+'/login/lianzu.png'" class="info-icon" v-if="item.type==1"></image>
					<image :src="imgStorage+'/login/gongzu.png'" class="info-icon" v-else-if="item.type==2"></image>
					<image :src="imgStorage+'/login/zhiguan.png'" class="info-icon" v-else-if="item.type==3"></image>
					<view class="title">
						{{item.areaName||''}}{{item.streetName||''}}{{item.buildingNumber||''}}#{{item.unitNumber||''}}-{{item.floorLevel||''}}0{{item.roomNumber||''}}
					</view>
				</view>
				<view class="time">租期：{{item.paymentStart}}至{{item.paymentEnd}}</view>
				<view class="rent-item">
					<view class="rent-itme">续租时间{{item.createTime}}</view>
					<view class="status" v-if="item.status==3" style="color: #ea0000;">待续租</view>
					<view class="status" v-if="item.status==1" style="color: #ffa100;">审核中</view>
					<view class="status" v-if="item.status==2" style="color: #18aa00;">续租成功</view>
				</view>
				<view class="btn-item" v-if="item.status==2||item.status==3">
					<!-- <view class="small-btn normal" v-if="item.status==3">续租</view> -->
					<view class="small-btn cancel">查看合同</view>
				</view>
			</view>
		</template>
		<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
		<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		<view class="invoice" @click="navigate('/page_pack/invoice/invoice')">若需开具发票，点击申请</view>
	</view>
</template>

<script>
	import {
		SelectHouse
	} from '@/components/SelectHouse.vue'
	import {
		isMore
	} from '@/util/util.js'
	import {
		setStorage,
		getStorage
	} from '@/util/auth.js';
	import {
		getFwRenewalApi
	} from '@/api/renewal.js'
	export default {
		components: {
			SelectHouse
		},
		data() {
			return {
				selectInfo: {},
				more: true,
				conf: {
					page: 1,
					limit: 10,
				},
				list: []
			}
		},
		methods: {
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			getList(refresh = false) {
				getFwRenewalApi({
					page: this.conf.page,
					limit: this.conf.limit,
					idValue: this.id
				}).then(res => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.total)
				})
			},
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList();
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getList(true)
		},
		onShow() {
			this.selectInfo = getStorage('selectInfo')
			this.id = this.selectInfo.idValue
		}
	}
</script>

<style lang="scss" scoped>
	.house-pages {
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.info-block {
			padding: 30rpx;
			background-color: #fff;
			margin-top: 20rpx;
			border-radius: 30rpx;

			.rent-info {
				display: flex;
				align-items: center;
				border-bottom: 1px solid #eeeeee;
				padding-bottom: 30rpx;
				margin-bottom: 30rpx;

				.info-icon {
					width: 40rpx;
					height: 40rpx;
					margin-right: 10rpx;
				}

				.title {
					width: calc(100% - 50rpx);
					font-size: 32rpx;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}

			.time {
				font-size: 30rpx;
				margin-bottom: 30rpx;
			}

			.rent-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 30rpx;

				.rent-itme {
					font-size: 28rpx;
					color: #767676;
				}

				.status {
					font-size: 28rpx;
				}
			}

			.btn-item {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				border-top: 1px solid #eeeeee;

				.small-btn {
					width: 150rpx;
				}
			}

		}

		.invoice {
			color: $theme-color;
			font-size: 28rpx;
			text-align: center;
			margin-top: 50rpx;
		}
	}
</style>